import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param s string字符串 
     * @return bool布尔型
     */
    public boolean isValid (String s) {
        // write code here
        Stack<Character> stack=new Stack<Character>();
        if(s.length()==1||s.length()==0){
            return  false;
        }
        stack.push(s.charAt(0));
        for(int i=1;i<s.length();i++){
if(!stack.empty()&&(s.charAt(i)==')'&&stack.peek()=='(')||(s.charAt(i)==']'&&stack.peek()=='[') ||(s.charAt(i)=='}'&&stack.peek()=='{'))
        {
stack.push(s.charAt(i));
stack.pop();
stack.pop();
        }else{
           stack.push(s.charAt(i));
        }
        }
        if(stack.empty()){
            return true;
        }
        return false;
    }
}









